package org.noranj.webservice;

import java.sql.SQLException;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.noranj.dto.ConversationDTO;
import org.noranj.service.ConversationManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;


@Path("/conversation/")
@Scope("request")
public class ConversationWS {
  
  ConversationManager conversationManager;
  
  public ConversationWS(){
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    conversationManager = (ConversationManager) ctx.getBean("conversationManagerImpl");
    }
  
  @POST
  @Path("/addrow/")
  public void insertConversation(ConversationDTO conversation)  {
      conversationManager.insertConversation(conversation);
  }
  
  @GET
  @Path("/conversations/")
  @Produces("application/json")
  public List<ConversationDTO> getConversations() {
    return conversationManager.getConversations();
  }
  
  @GET
  @Path("/about")
  @Produces("application/json")
  public String about() {
    return("My Service version 1.0");
  } 
  
  
}
